package com.qf.j2112.controller;

import com.qf.j2112.anno.JWTAnno;
import com.qf.j2112.service.DataService;
import com.qf.j2112.vo.ActionResultVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@RestController
@RequestMapping("/api")
@CrossOrigin
public class DataController {

    @Resource
    private DataService dataService;

    @JWTAnno(name = "获取访问量")
    @GetMapping("/visits")
    public ActionResultVO getVisitNum(){
        List<Map<Date, Integer>> vistNumPerDay = dataService.getVistNumPerDay();
        return new ActionResultVO(200,"查询成功",vistNumPerDay);
    }

    @JWTAnno(name = "获取销售额分布")
    @GetMapping("/sells")
    public ActionResultVO getSellNum(){
        List<Map<Integer, String>> sellNum = dataService.getVistSellNum();
        return new ActionResultVO(200,"查询成功",sellNum);
    }

    @JWTAnno(name = "分布销售额时间分布")
    @GetMapping("/sellday")
    public ActionResultVO getSellNumData(){
        Integer all=dataService.sellMoney();
        Integer day=dataService.DaysellMoney();
        Integer week=dataService.WeeksellMoney();
        Integer month=dataService.MonthsellMoney();
        String[] s={"总销售额","今日销售额","周销售额","月销售额"};
        Integer[] n={all,day,week,month};
        List list=new ArrayList();
        list.add(s);
        list.add(n);
        return new ActionResultVO(200,"查询成功",list);
    }
}
